3D Graphics Programming with QuickDraw 3D 1.5.4
Previous | QD3D Book | Overview | Chapter Contents | Next |
The data in an 3DMF file is organized into discrete units called metafile objects (or, more briefly, and despite the risk of confusion with QuickDraw 3D objects, objects ). You read data from an 3DMF file by reading each individual metafile object in it (by calling the Q3File_ReadObject function), until you reach the end of the file. Listing 5 illustrates how to read the metafile objects in an 3DMF file.
The My Read3DMFModel function defined in Listing 5 opens a file object and sequentially reads each metafile object in the 3DMF file into a QuickDraw 3D object. My Read3DMFModel determines the type of the QuickDraw 3D object read. If the object is a view hints object, My Read3DMFModel returns that object in the viewHints parameter. If the object isn't a view object, it must be some other drawable QuickDraw 3D object. In that case, My Read3DMFModel either returns that object in the model parameter (if there are no more objects in the 3DMF file) or adds it to a display group. When it executes successfully, My Read3DMFModel returns both a 3D model and a view hints object to its caller.
Listing 5 Reading metafile objects
TQ3Status MyRead3DMFModel
(TQ3FileObject file, TQ3Object *model, TQ3Object *viewHints)
{
TQ3Object myGroup;
TQ3Object myObject;
/*Initialize view hints and model to be returned.*/
*viewHints = NULL;
*model = NULL;
myGroup = NULL;
myObject = NULL;
/*Open the file object and exit gracefully if unsuccessful.*/
if (Q3File_OpenRead(file, NULL) != kQ3Success)
{
DoError("MyRead3DMFModel", "Reading failed %s", filename);
return kQ3Failure;
}
while (Q3File_IsEndOfFile(file) == kQ3False)
{
myObject = NULL;
/*Read a metafile object from the file object.*/
myObject = Q3File_ReadObject(file);
if (myObject == NULL)
continue;
/*Save a view hints object, and add any drawable objects to a group.*/
if (Q3Object_IsType(myObject, kQ3SharedTypeViewHints))
{
if (*viewHints == NULL)
{
*viewHints = myObject;
myObject = NULL;
}
}
else if (Q3Object_IsDrawable(myObject))
{
if (myGroup)
{
Q3Group_AddObject(myGroup, myObject);
}
else if (*model == NULL)
{
*model = myObject;
myObject = NULL;
}
else
{
myGroup = Q3DisplayGroup_New();
Q3Group_AddObject(myGroup, *model);
Q3Group_AddObject(myGroup, myObject);
Q3Object_Dispose(*model);
*model = myGroup;
}
}
if (myObject != NULL)
Q3Object_Dispose(myObject);
}
if (Q3Error_Get(NULL) != kQ3ErrorNone)
{
if (*model != NULL) {
Q3Object_Dispose(*model);
*model = NULL;
}
if (*viewHints != NULL) {
Q3Object_Dispose(*viewHints);
*viewHints = NULL;
}
return (kQ3Failure);
}
return kQ3Success;
}
Previous | QD3D Book | Overview | Chapter Contents | Next |